<template>
  <base-breadcrumb>
    <a-card class="mb20">
      <titleName
        ref="box"
        title="会议发起"
      />
      <a-form-model
        ref="ruleForm"
        :model="form"
        :rules="rules"
        :label-col="{ span: 6 }"
        :wrapper-col="{ span: 16 }"
      >
        <a-row :gutter="24">
          <a-col
            v-if="!meetingType"
            :md="24"
            :sm="24"
          >
            <a-form-model-item label="会议类型：">
              <a-radio-group
                v-model="form.value"
                class="mb20"
                :options="meetingTypeList"
                @change="changeValue"
              />
              <!-- <a-radio-group v-model="form.value" @change="onChangeRadio">
                  <a-radio :value="1">施工方案评审会议</a-radio>
                  <a-radio :value="2">专业分包方案讲评</a-radio>
                  <a-radio :value="3">危险源识别清单发布</a-radio>
                  <a-radio :value="4">项目月度经营分享会</a-radio>
                  <a-radio :value="5">安全教育记录</a-radio>
                  <a-radio :value="6">安全关键会议</a-radio>
                  <a-radio :value="7">施工方案交底记录</a-radio>
                  <a-radio :value="8">监理例会</a-radio>
                  <a-radio :value="9">设计例会</a-radio>
              </a-radio-group> -->
            </a-form-model-item>
          </a-col>
          <a-col
            :md="16"
            :sm="16"
          >
            <a-form-model-item
              label="所属单位："
              prop="projectId"
            >
              <org-tree-select
                v-model="form.projectId"
                is-need-auth
                is-auto-select-first
                check-strictly
                @select="changeProject"
              />
            </a-form-model-item>
          </a-col>
          <!--          <a-col-->
          <!--            :md="8"-->
          <!--            :sm="8"-->
          <!--          >-->
          <!--            <a-form-model-item-->
          <!--              label="所属分公司："-->
          <!--              prop="branchComId"-->
          <!--            >-->
          <!--              <SelectSubCompany-->
          <!--                v-model="form.branchComId"-->
          <!--                placeholder="请选择"-->
          <!--              />-->
          <!--            </a-form-model-item>-->
          <!--          </a-col>-->
          <!--          <a-col-->
          <!--            :md="8"-->
          <!--            :sm="8"-->
          <!--          >-->
          <!--            <a-form-model-item-->
          <!--              label="所属项目："-->
          <!--              prop="projectId"-->
          <!--            >-->
          <!--              <SelectProject-->
          <!--                v-model="form.projectId"-->
          <!--                placeholder="请选择"-->
          <!--                :form="form"-->
          <!--                :is-clear="id == ''"-->
          <!--                key-value="branchComId"-->
          <!--                @change="changeProject"-->
          <!--              />-->
          <!--            </a-form-model-item>-->
          <!--          </a-col>-->
          <a-col
            v-if="form.value == 4"
            :md="8"
            :sm="8"
          >
            <a-form-model-item
              label="月份："
              prop="month"
            >
              <a-month-picker
                v-model="form.month"
                placeholder="请输入"
                @change="(date, dateString) => getTime(date, dateString, 'form', 'month')"
              />
            </a-form-model-item>
          </a-col>
          <a-col
            v-if="form.value == 7"
            :md="8"
            :sm="8"
          >
            <a-form-model-item
              label="交底方案："
              prop="confessId"
            >
              <a-select
                v-model="form.confessId"
                placeholder="请选择"
                @change="changeCommentedPlan2"
              >  <a-spin v-if="fetching" slot="notFoundContent" size="small" />
                 <a-icon v-if="fetching" style="color: #096dd9" slot="suffixIcon" type="loading" />
                <a-select-option
                  v-for="item in disclosurePlan"
                  :key="item.id"
                  :value="item.id"
                >
                  {{
                    item.name
                  }}
                </a-select-option>
              </a-select>
            </a-form-model-item>
          </a-col>
          <a-col
            :md="8"
            :sm="8"
          >
            <a-form-model-item
              label="会议名称："
              prop="meetingName"
            >
              <BaseInput
                v-model.trim="form.meetingName"
                :max-length="30"
                placeholder="请输入"
              />
            </a-form-model-item>
          </a-col>
          <a-col    v-if="form.value == 7"
            :md="8"
            :sm="8"
          >
            <a-form-model-item
              label="是否为专业分包方案："
              prop="isProSubName"
            >
              <BaseInput
                v-model="form.isProSubName"
                :max-length="30"
                placeholder="请输入"
                disabled
              />
            </a-form-model-item>
          </a-col>
          <a-col    v-if="form.value == 7"
            :md="8"
            :sm="8"
          >
            <a-form-model-item
              label="方案类型："
              prop="planType"
            >
              <BaseInput
                v-model="form.planType"
                :max-length="30"
                placeholder="请输入"
                disabled
              />
            </a-form-model-item>
          </a-col>
          <a-col    v-if="form.value == 7"
            :md="8"
            :sm="8"
          >
            <a-form-model-item
              label="现行版本："
              prop="currentVersion"
            >
              <BaseInput
                v-model="form.currentVersion"
                :max-length="30"
                placeholder="请输入"
                disabled
              />
            </a-form-model-item>
          </a-col>
          <a-col    v-if="form.value == 7"
            :md="8"
            :sm="8"
          >
            <a-form-model-item
              label="编制人员："
              prop="programmer"
            >
              <BaseInput
                v-model.trim="form.programmer"
                :max-length="30"
                placeholder="请输入"
                disabled
              />
            </a-form-model-item>
          </a-col>
          <a-col
            :md="8"
            :sm="8"
          >
            <a-form-model-item
              label="主持人/主讲人："
              prop="speaker"
            >
              <!-- <BaseInput :maxLength="30" placeholder="请输入" v-model.trim="form.speaker" /> -->
              <SelectPersonByProject
                :id="form.branchCompanyId"
                v-model="form.speaker"
                :project-id="form.projectId"
                :show-search="true"
                mode="combobox"
                placeholder="请选择"
                option-label-prop="children"
              />
            </a-form-model-item>
          </a-col>
          <a-col
            :md="8"
            :sm="8"
          >
            <a-form-model-item
              label="会议地点："
              prop="meetingPlace"
            >
              <BaseInput
                v-model.trim="form.meetingPlace"
                :max-length="300"
                placeholder="请输入"
              />
            </a-form-model-item>
          </a-col>

          <a-col
            :md="8"
            :sm="8"
          >
            <a-form-model-item
              label="会议时间："
              prop="startTime"
            >
              <a-date-picker
                v-model="form.startTime"
                :show-time="{ format: 'HH:mm' }"
                format="YYYY-MM-DD HH:mm"
                placeholder="请选择"
                @change="(date, dateString) => getTime(date, dateString, 'form', 'startTime')"
              />
            </a-form-model-item>
          </a-col>
          <a-col    v-show="form.value == 7 && form.isProSub"
            :md="8"
            :sm="8"
          >
            <a-form-model-item
              label="参会人数："
              :prop="(form.value == 7 && form.isProSub) ? 'meetingCount': '' "
            >
            <BaseInputNumber
                v-model.trim="form.meetingCount"
                :min="0"
                placeholder="请输入"
              />
            </a-form-model-item>
          </a-col>
          <!-- v-if="form.value == 7" -->
          <a-col v-if="form.value == 7"
            :md="8"
            :sm="8"
          >
            <a-form-model-item
              label="交底人："
              prop="confessUserId"
            >
  
              <SelectPersonByProject
                :id="form.branchCompanyId"
                v-model="form.confessUserId"
                :project-id="form.projectId"
                :show-search="true"
                mode="combobox"
                :allowClear="true"
                option-label-prop="children"
                @personChanged="personChanged"
              />
            </a-form-model-item>
          </a-col>
          <a-col
            :md="24"
            :sm="24"
          >
            <a-form-model-item
              label="会议说明："
              prop="meetingExplains"
            >
              <BaseTextarea
                v-model.trim="form.meetingExplains"
                :max-length="300"
                placeholder="请输入"
              />
            </a-form-model-item>
          </a-col>
          <a-col
            :md="24"
            :sm="24"
            v-if="form.value == 7 && form.isProSub"
          >
            <a-form-model-item
              label="主要参会人员："
              prop="mainParticipants"
            >
              <BaseTextarea
                v-model.trim="form.mainParticipants"
                :max-length="300"
                placeholder="请输入"
              />
            </a-form-model-item>
          </a-col>
        </a-row>
      </a-form-model>
      <!-- 施工方案评审会议 -->
      <a-form-model
        v-show="form.value == '1'"
        ref="ruleForm1"
        :model="form"
        :rules="rulesType1"
        :label-col="{ span: 6 }"
        :wrapper-col="{ span: 16 }"
      >
        <a-row :gutter="24">
          <a-col
            :md="8"
            :sm="8"
          >
            <a-form-model-item
              label="评审方案："
              prop="commentedPlan"
            >
              <a-select
                v-model="form.commentedPlan"
                placeholder="请选择"
                @change="changeReviewPlan"
              >
                <a-select-option
                  v-for="item in reviewPlan"
                  :key="item.id"
                  :value="item.id"
                >
                  {{
                    item.name
                  }}
                </a-select-option>
              </a-select>
            </a-form-model-item>
          </a-col>

          <a-col
            :md="8"
            :sm="8"
          >
            <a-form-model-item
              label="方案编制人"
              prop="programmer"
            >
              <BaseInput
                v-model.trim="form.programmer"
                disabled
                placeholder="请输入"
              />
            </a-form-model-item>
          </a-col>
          <a-col
            :md="24"
            :sm="24"
          >
            <a-form-model-item
              label="其他评审人员："
              prop="otherReviewer"
            >
              <BaseTextarea
                v-model.trim="form.otherReviewer"
                :max-length="300"
                placeholder="请输入"
              />
            </a-form-model-item>
          </a-col>
        </a-row>
      </a-form-model>
      <!-- 专业分包方案讲评 -->
      <a-form-model
        v-show="form.value == '2'"
        ref="ruleForm2"
        :model="form"
        :rules="rulesType2"
        :label-col="{ span: 6 }"
        :wrapper-col="{ span: 16 }"
      >
        <a-row :gutter="24">
          <a-col
            :md="8"
            :sm="8"
          >
            <a-form-model-item
              label="讲评方案："
              prop="commentedPlan"
            >
              <a-select
                v-model="form.commentedPlan"
                placeholder="请选择"
                @change="changeCommentedPlan"
              >
                <a-select-option
                  v-for="item in constructionProgram"
                  :key="item.id"
                  :value="item.id"
                >
                  {{
                    item.name
                  }}
                </a-select-option>
              </a-select>
            </a-form-model-item>
          </a-col>
          <a-col
            :md="8"
            :sm="8"
          >
            <a-form-model-item
              label="方案编制人："
              prop="programmer"
            >
              <BaseInput
                v-model.trim="form.programmer"
                disabled
                placeholder="请输入"
              />
            </a-form-model-item>
          </a-col>
          <template v-if="form.value == 2">
          <a-col :md="8" :sm="8">
            <a-form-model-item label="方案类型：">
              <BaseInput disabled placeholder="加载中" v-model="form.planType"></BaseInput>
            </a-form-model-item>
          </a-col>
          <a-col :md="8" :sm="8">
            <a-form-model-item label="现行版本：">
              <BaseInput disabled placeholder="加载中" v-model="form.currentVersion"></BaseInput>
            </a-form-model-item>
          </a-col>
          </template>
          <a-col
            :md="8"
            :sm="8"
          >
            <a-form-model-item
              label="专业单位名称："
              prop="professionComName"
            >
              <SelectSubcontractor
                v-model="form.professionComName"
                placeholder="请选择"
                :form="form"
                :is-clear="id == ''"
                key-value="projectId"
              />
            </a-form-model-item>
          </a-col>
        </a-row>
      </a-form-model>
      <!-- 危险源识别清单发布 -->
      <a-form-model
        v-show="form.value == '3'"
        ref="ruleForm3"
        :model="form"
        :rules="rulesType3"
        :label-col="{ span: 6 }"
        :wrapper-col="{ span: 16 }"
      >
        <a-row :gutter="24">
          <a-col
            :md="8"
            :sm="8"
          >
            <a-form-model-item
              label="会议月份："
              prop="hsemonth"
            >
              <a-month-picker
                v-model="form.hsemonth"
                placeholder="请输入"
                @change="(date, dateString) => getTime(date, dateString, 'form', 'hsemonth')"
              />
            </a-form-model-item>
          </a-col>
          <a-col
            :md="8"
            :sm="8"
          >
            <a-form-model-item
              label="当前施工阶段："
              prop="currentConstructionStage"
            >
              <BaseInput
                v-model.trim="form.currentConstructionStage"
                :max-length="30"
                placeholder="请输入"
              />
            </a-form-model-item>
          </a-col>
        </a-row>
      </a-form-model>
      <!-- 安全教育记录 -->
      <a-form-model
        v-show="form.value == '5'"
        ref="ruleForm5"
        :model="form"
        :rules="rulesType5"
        :label-col="{ span: 6 }"
        :wrapper-col="{ span: 16 }"
      >
        <a-row :gutter="24">
          <a-col
            :md="8"
            :sm="8"
          >
            <a-form-model-item
              label="教育课时："
              prop="educationHour"
            >
              <BaseInput
                v-model.trim="form.educationHour"
                :max-length="30"
                placeholder="请输入"
              />
            </a-form-model-item>
          </a-col>
          <a-col
            :md="8"
            :sm="8"
          >
            <a-form-model-item
              label="教育负责人："
              prop="educationResponsible"
            >
              <SelectPersonByProject
                :id="form.branchCompanyId"
                v-model="form.educationResponsible"
                :project-id="form.projectId"
                :show-search="true"
              />
              <!-- <OrgStaffAsync
                  placeholder="请选择"
                  v-model="form.educationResponsible"
                  :disableCheckbox="true"
                  :orgCheckable="true"
                  :selectedValue.sync="form.educationResponsible"
                  :treeCheckable="false"
              /> -->
              <!-- <BaseInput placeholder="请输入" v-model.trim="form.educationResponsible" /> -->
            </a-form-model-item>
          </a-col>
          <a-col
            :md="24"
            :sm="24"
          >
            <a-form-model-item
              label="受教育单位："
              prop="educationOrganization"
            >
              <BaseTextarea
                v-model.trim="form.educationOrganization"
                placeholder="请输入"
              />
            </a-form-model-item>
          </a-col>
        </a-row>
      </a-form-model>
      <!-- 施工方案交底记录 -->
      <a-form-model
        v-show="form.value == '7'"
        ref="ruleForm7"
        :model="form"
        :rules="rulesType7"
        :label-col="{ span: 6 }"
        :wrapper-col="{ span: 16 }"
      >
        <!-- <a-row :gutter="24">
          <a-col
            :md="8"
            :sm="8"
          >
            <a-form-model-item
              label="参会人数："
              prop="meetingCount"
            >
              <BaseInputNumber
                v-model.trim="form.meetingCount"
                :min="0"
                placeholder="请输入"
              />
            </a-form-model-item>
          </a-col>
          <a-col
            :md="24"
            :sm="24"
          >
            <a-form-model-item
              label="主要参会人员："
              prop="mainParticipants"
            >
              <BaseTextarea
                v-model.trim="form.mainParticipants"
                :max-length="300"
                placeholder="请输入"
              />
            </a-form-model-item>
          </a-col>
        </a-row> -->
      </a-form-model>
      <!-- 监理例会 设计例会 -->
      <a-form-model
        v-show="form.value == '8' || form.value == '9'"
        ref="ruleForm8"
        :model="form"
        :rules="rulesType8"
        :label-col="{ span: 6 }"
        :wrapper-col="{ span: 16 }"
      >
        <a-row :gutter="24">
          <a-col
            :md="8"
            :sm="8"
          >
            <a-form-model-item
              label="参会人数："
              prop="meetingCount"
            >
              <BaseInputNumber
                v-model.trim="form.meetingCount"
                :min="0"
                placeholder="请输入"
              />
            </a-form-model-item>
          </a-col>
          <a-col
            :md="24"
            :sm="24"
          >
            <a-form-model-item
              label="主要参会人员："
              prop="mainParticipants"
            >
              <BaseTextarea
                v-model.trim="form.mainParticipants"
                :max-length="300"
                placeholder="请输入"
              />
            </a-form-model-item>
          </a-col>
        </a-row>
      </a-form-model>
    </a-card>
    <a-card class="mb20">
      <a-form-model
        :model="form"
        :label-col="{ span: 6 }"
        :wrapper-col="{ span: 16 }"
      >
        <div v-if="form.value == '8' || form.value == '9' || (form.value == '7' && form.isProSub)">
          <a-row :gutter="24">
            <a-col span="24">
              <a-form-model-item
                label="会议纪要"
                prop="meetingSummary"
              >
                <!-- <editor
                    v-model.trim="form.meetingSummary"
                    :isClear="true"
                     :maxLength="30000"
                    @change="commentsVal"
                ></editor> -->
                <BaseTextarea
                  v-model="form.meetingSummary"
                  :auto-size="{ minRows: 20, maxRows: 25 }"
                  :max-length="30000"
                  placeholder="请输入"
                />
              </a-form-model-item>
            </a-col>
          </a-row>
        </div>
        <div v-else>
          <a-row :gutter="24">
            <a-col
              :md="24"
              :sm="24"
            >
              <a-form-model-item
                label="参会者选择："
                prop="meetingEmployeeDTOList"
              >
                <!-- <OrgStaffAsync
                    placeholder="请选择/多选"
                    v-model="form.meetingEmployeeDTOList"

                    :orgCheckable="true"
                    :selectedValue.sync="form.meetingEmployeeDTOList"
                    :treeCheckable="true"
                /> -->

                <!-- <a-col :span="20"> -->
                <!-- 操作栏 -->
                <div class="mb12">
                  <a-button
                    icon="plus"
                    class="btn_right"
                    type="primary"
                    @click="openSelectPersonModal"
                  >
                    添加人员
                  </a-button>
                  <a-button
                    :disabled="rowSelection.selectedRowKeys.length < 1"
                    icon="delete"
                    type="danger"
                    @click="handleRemoveMore"
                  >
                    移除
                  </a-button>
                </div>
                <!-- 统计选中项 -->
                <a-alert :show-icon="true">
                  <template slot="message">
                    <span style="margin-right: 12px">
                      已选择:
                      <a>
                        <b>{{ rowSelection.selectedRowKeys.length }}</b>
                      </a>
                      项
                    </span>
                  </template>
                </a-alert>
                <!-- 表格 -->
                <s-table
                  ref="tableEmployee"
                  table-layout="fixed"
                  size="default"
                  row-key="id"
                  :columns="columnsEmployee"
                  :data="loadDataEmployee"
                  :alert="true"
                  :row-selection="rowSelection"
                  show-size-changer
                  show-quick-jumper
                  show-pagination="auto"
                >
                  <!-- 表格行操作栏 -->
                  <span
                    slot="actions"
                    slot-scope="text, record, index"
                  >
                    <template>
                      <!-- <a @click="handleManage(record)">查看</a>
                                        <a-divider type="vertical" /> -->
                      <a @click="handleRemove(index)">移除</a>
                    </template>
                  </span>
                </s-table>
              </a-form-model-item>
              <!-- </a-col> -->
            </a-col>
          </a-row>
        </div>
        <a-col :md="24" :sm="24"   v-if="form.value == 7 && form.isProSub">
            <a-form-model-item label="现场照片" prop="sitPhotoList">
                <upload-list
                    :businessCode="'BM24'"
                    :uploadArrys.sync="form.sitPhotoList"
                    @fileArrysData="handleFileUploaded"
                    uploadType="image"
                    :editModel="2"
                    multiple
                ></upload-list>
            </a-form-model-item>
        </a-col> 
        <a-col v-if="form.value == 7 && form.isProSub" :md="24" :sm="24">
            <a-form-model-item label="附件上传" prop="summaryFileList">
                <upload-list
                    :businessCode="'BM24'"
                    :uploadArrys.sync="form.summaryFileList"
                    @fileArrysData="handleFileUploaded2"
                    :editModel="2"
                    multiple
                ></upload-list>
            </a-form-model-item>
        </a-col>
      </a-form-model>
    </a-card>
    <a-card
      v-if="form.value == '8' || form.value == '9'"
      class="mb20"
    >
      <titleName
        title="相关资料上传"
        class="title-style"
      />
      <div class="table-operator row">
        <l-table
          upload-type="normal"
          text="新增"
          btn-type="primary"
          :upload-arrys="form.fileList"
          business-code="SHE04"
          @fileArrysData="fileArrysData"
        />

        <!-- <a-button class="ml20">删除</a-button> -->
      </div>
      <s-table
        ref="table"
        size="default"
        row-key="key"
        :columns="columns"
        :data="loadData"
        :alert="true"
        show-size-changer
        show-quick-jumper
        :show-pagination="false"
      >
        <span
          slot="serial"
          slot-scope="text, record, index"
        >{{ index + 1 }}</span>
        <span
          slot="action"
          slot-scope="text, record, index"
        >
          <a
            :href="
              '/api/ycloud-file-center/oper/download?access_token=' + token + '&fileId=' + record.fileId
            "
          >下载</a>
          <a-divider
            type="vertical"
          />
          <a
            href="javascript:"
            @click="$filePreview(record)"
          >预览</a>
          <a-divider type="vertical" />
          <a @click="delItem(index)">删除</a>
        </span>
      </s-table>
    </a-card>
    <div class="tool-btns page-btn-right-top">
      <a-button
        class="ml20"
        :loading="loading"
        type="primary"
        @click="addMeeting"
      >
        提交
      </a-button>
      <a-button
        class="ml20"
        type="primary"
        @click="handleClose"
      >
        关闭
      </a-button>
    </div>

    <!-- 表单弹窗 -->
    <dialog-edit
      ref="dialogEdit"
      :meeting-employee-d-t-o-list-data="form.meetingEmployeeDTOListData"
      :visible.sync="visible"
      @confirm="submitForm"
      @confirms="submitForms"
    />
    <SelectPerson
      ref="SelectPersonWithTree"
      header-title="添加参会人员"
      :un-repeat-person="true"
      @confirm="submitForms"
    />
  </base-breadcrumb>
</template>
<script>
const columnsEmployee = [
  {
    title: "员工名称",
    dataIndex: "name"
  },

  {
    title: "电话号码",
    dataIndex: "phone"
  },

  {
    title: "操作",
    dataIndex: "actions",
    width: "100px",
    scopedSlots: { customRender: "actions" }
  }
]
const columns = [
  {
    title: "序号",
    dataIndex: "serial",
    width: "5%",
    scopedSlots: { customRender: "serial" }
  },
  {
    title: "文件名称",
    dataIndex: "fileName",
    width: "40%"
  },
  {
    title: "文件格式",
    dataIndex: "suffixName"
  },
  {
    title: "操作",
    dataIndex: "action",
    width: "10%",
    scopedSlots: { customRender: "action" }
  }
]

import SelectSubCompany from "@/components/Select/SelectSubCompany" // 分公司
import SelectPersonByProject from "@/components/Select/SelectPersonByProject" // 分公司
import SelectProject from "@/components/Select/SelectProject" // 分公司
import SelectSubcontractor from "@/components/Select/SelectSubcontractor" // 分包商
import { STable } from "@/components"
import dialogEdit from "./dialogEdit.vue" // 表单弹窗
import { getProjectInfo } from "@/api/businessAffairs/revenueAndCost"
import SelectPerson from '@/components/BComponents/BSelectPerson'
import UploadList from '@/components/UploadList'
import {
  getMeetingType,
  addMeeting,
  getConstructionProgram,
  getReviewPlan,
  getTechnicalProgramList
  } from "@/api/office/conference"
import Vue from "vue"

export default {
  name: "a" + Date.now(),
  components: {
    SelectSubCompany,
    SelectProject,
    STable,
    SelectSubcontractor,
    SelectPersonByProject,
    dialogEdit,
    SelectPerson,
    UploadList
  },
  data() {
    return {
      columns,
      columnsEmployee,
      meetingType: false,
      token: Vue.getAcloudProvider().getAccessToken(),
      form: {
        educationHour: "",
        educationResponsible: "",
        educationOrganization: "",
        value: 1,
        meetingSummary: "",
        fileList: [],
        meetingEmployeeDTOList: [],
        meetingEmployeeDTOListData: [],
        branchComId: "",
        projectId: "",
        name: "",
        meetingName: "",

        startTime: "",
        meetingExplains: "",
        commentedPlan: "",
        programmer: "",
        otherReviewer: "",
        professionComName: "",
        hsemonth: "",
        currentConstructionStage: "",
        meetingCount: "",
        mainParticipants: "",
        sitPhotoList:[],
        summaryFileList:[],
        currentVersion: '',
        planType: '',
      },
      rulesType: {
        branchComId: [{ required: true, message: "请选择分公司", trigger: "blur" }],
        projectId: [{ required: true, message: "请选择项目" }],
        name: [{ required: true, message: "请输入名称" }],

      },
      rules: {
        month: [{ required: true, message: "请选择月份" }],
        commentedPlan: [{ required: true, message: "请选择交底方案", trigger: "blur" }],
        confessId: [{ required: true, message: "请选择交底方案", trigger: "blur" }],
        branchComId: [{ required: true, message: "请选择分公司", trigger: "blur" }],
        projectId: [{ required: true, message: "请选择项目", trigger: "blur" }],
        meetingName: [{ required: true, message: "请输入名称", trigger: "blur" }],
        speaker: [{ required: true, message: "请输入主持人/主讲人", trigger: "blur" }],
        meetingPlace: [{ required: true, message: "请输入会议地点", trigger: "blur" }],
        startTime: [{ required: true, message: "请输入会议时间", trigger: "change" }],
        meetingExplains: [{ required: true, message: "请输入会议说明", trigger: "blur" }],
        mainParticipants: [{ required: true, message: "请输入主要参会人员", trigger: "blur" }],
        meetingCount: [{ required: true, message: "请输入参会人数", trigger: "blur" }],
        confessUserId: [{ required: true, message: "请选择交底人", trigger: "blur" }],
      },
      rulesType1: {
        commentedPlan: [{ required: true, message: "请选择评审方案", trigger: "blur" }],
        programmer: [{ required: true, message: "请选择方案编制人", trigger: "blur" }],
        otherReviewer: [{ required: true, message: "请选择其他评审人员", trigger: "blur" }]
      },
      rulesType2: {
        commentedPlan: [{ required: true, message: "请选择讲评方案", trigger: "blur" }],
        programmer: [{ required: true, message: "请选择方案编制人", trigger: "blur" }],
        professionComName: [{ required: true, message: "请选择专业单位名称", trigger: "blur" }]
      },
      rulesType3: {
        hsemonth: [{ required: true, message: "请输入月份", trigger: "change" }],
        currentConstructionStage: [{ required: true, message: "请输入当期施工阶段", trigger: "blur" }]
      },
      rulesType5: {
        educationHour: [{ required: true, message: "请输入教育课时", trigger: "blur" }],
        educationResponsible: [{ required: true, message: "请选择教育负责人", trigger: "change" }],
        educationOrganization: [{ required: true, message: "请输入受教育单位", trigger: "blur" }]
      },

      rulesType7: {
        commentedPlan: [{ required: true, message: "请选择交底方案", trigger: "blur" }],
        // disclosurePlan: [{ required: true, message: '请输入交底方案', trigger: 'blur' }],
        meetingCount: [{ required: true, message: "请输入参会人数", trigger: "blur" }],
        mainParticipants: [{ required: true, message: "请输入主要参会人员", trigger: "blur" }]
      },

      rulesType8: {
        meetingCount: [{ required: true, message: "请输入参会人数", trigger: "blur" }],
        mainParticipants: [{ required: true, message: "请输入主要参会人员", trigger: "blur" }]
      },

      loadData: () => {
        return new Promise((resolve, reject) => {
          resolve({
            data: this.form.fileList
          })
        })
      },
      loadDataEmployee: (parameter) => {
        return new Promise((resolve, reject) => {
          let obj = {}
          obj.currentPage = parameter.pageNo
          obj.pageSize = parameter.pageSize
          obj.totalPage = Math.ceil(this.form.meetingEmployeeDTOListData.length / parameter.pageSize)
          obj.totalSize = this.form.meetingEmployeeDTOListData.length
          obj.data = this.form.meetingEmployeeDTOListData || []
          console.log(obj)
          resolve(obj)
        })
      },
      loading: false,
      id: "",
      isUpdate: true,
      meetingTypeList: [], //会议类别
      constructionProgram: [],
      reviewPlan: [],
      disclosurePlan: [],
      applicationGroupPlan:[],  //施组交底方案
      visible: false,
      // 表格复选框配置
      rowSelection: {
        selectedRowKeys: [],
        onChange(selectedRowKeys) {
          this.selectedRowKeys = selectedRowKeys
        }
      },
      selectedKeys: [], // 选中节点
      selectOptions: {}, // 选中节点对象
      projectDeptOrgId: "",//项目所在的树节点Id
      fetching:false,
    }
  },
  mounted() {
    this.getMeetingType()
    this.meetingType = false
    if (this.$route.query.typeId) {
      this.form.value = this.$route.query.typeId
      this.meetingType = true
      this.initTitle()
    }
  },

  methods: {
    personChanged(e, record) {
       this.$set(this.form,'confessUserName', e?.employeeName);
    },
      handleFileUploaded(list) {
      this.form.sitPhotoList = [...list]
    },
    handleFileUploaded2(list) {
      this.form.summaryFileList = [...list]
    },
    openSelectPersonModal() {
      const list = this.form.meetingEmployeeDTOListData;
      this.$refs.SelectPersonWithTree.open(list)
    },
    // 提交表单
    submitForm(e) {
      this.form.meetingEmployeeDTOListData.push(e)
      console.log(this.form.meetingEmployeeDTOListData)
      this.$refs.tableEmployee.refresh(true)
    },
    submitForms(e) {
      e.forEach((item) => {
        this.form.meetingEmployeeDTOListData.push(item)
      })
    },
    handleRemove(index) {
      this.form.meetingEmployeeDTOListData.splice(index, 1)
      this.$refs.tableEmployee.refresh(true)
    },
    // 移除表格选中项
    handleRemoveMore() {
      // 若有选中项
      let that = this
      that.$confirm({
        title: "温馨提示",
        content: "确定移除这些数据？",
        okText: "确认",
        okType: "danger",
        cancelText: "取消",
        onOk() {
          console.log(that.rowSelection.selectedRowKeys)
          for (let index = 0; index < that.form.meetingEmployeeDTOListData.length; index++) {
            let item = that.form.meetingEmployeeDTOListData[index]
            console.log(index, item.id)
            if (that.rowSelection.selectedRowKeys.includes(item.id)) {
              that.form.meetingEmployeeDTOListData.splice(index, 1)
              index--
            }
          }
          that.$refs.tableEmployee.clearSelected()
          that.$refs.tableEmployee.refresh(true)
          // console.log(that.rowSelection.selectedRowKeys)
        }
      })
    },
    getProjectInfo(id) {
      let params = {
        projectId: id
      }

      getProjectInfo(params).then((res) => {
        this.projectDeptOrgId = res.data.projectDeptOrgId
        this.form.meetingEmployeeDTOListData = []
        this.$refs.tableEmployee?.refresh(true)
        console.log(res)
      })
    },
    changeProject(val) {
      //清空数据
      let arr = ['confessId', 'meetingName', 'currentVersion', 'speaker','isProSubName','planType','currentVersion','programmer','confessUserId']
      arr.forEach((item) => {
        this.$set(this.form, item, '')
      })
      console.log('this.form',)
      this.form.branchComId = val[val.length - 2].orgId
      if(this.form.projectId){
        this.getConstructionProgram(this.form.projectId) //获取专业分包
        this.getReviewPlan(this.form.projectId) //获取评审方案
        this.getDisclosurePlanReq(this.form.projectId)
        this.getProjectInfo(this.form.projectId)
      }

    },
    changeCommentedPlan(id) {
      let obj = this.constructionProgram.filter(
              (item) => this.form.commentedPlan == item.id
      )[0]
      this.form.programmer = obj?.creatorName
      if (this.form.value == 7) {
        this.form.meetingName =
          this.disclosurePlan.filter((item) => this.form.commentedPlan == item.id)[0].name + "交底会"
      }
      if(this.form.value == 2) {
        this.form.planType = obj?.planType
        this.form.currentVersion = obj?.currentVersion
      }
      console.log(this.form)
    },
    changeCommentedPlan2(id){
      let findData = this.disclosurePlan.find((item)=>item.id == id) || {};
      if(findData.id && this.form.value == '7'){  //施组方案交底新增会议
        let isProSubName= findData.isProSub?'是':'否';
        this.$set(this.form,'isProSub', findData.isProSub)
        this.$set(this.form,'isProSubName', isProSubName)
        this.$set(this.form,'planType', findData.planType)
        this.$set(this.form,'currentVersion', findData.currentVersion)
        this.$set(this.form,'programmer', findData.creatorName)
        this.$set(this.form,'confessName', findData.name)
      }else{
        let obj = this.constructionProgram.filter((item) => this.form.confessId == item.id)[0]
        this.form.programmer = obj?.creatorName
      }
      if (this.form.value == 7) {
        this.form.meetingName =
          this.disclosurePlan.filter((item) => this.form.confessId == item.id)[0].name + "交底会"
      }
    },
    changeReviewPlan(id) {
      this.form.programmer = this.reviewPlan.filter((item) => this.form.commentedPlan == item.id)[0].creatorName
    },
    async getReviewPlan(projectId) {
      const [err, res] = await getReviewPlan({ projectId: projectId, typeId: this.form.value })
      if (!err) {
        this.reviewPlan = res.data
      }
    },
    async getConstructionProgram(projectId) {
      const [err, res] = await getConstructionProgram({ projectId: projectId, typeId: this.form.value })
      if (!err) {
        this.constructionProgram = res.data
      }
    },
    async getDisclosurePlanReq(projectId) {
      this.disclosurePlan = [];
      this.fetching = true;
      const [err, res] = await getTechnicalProgramList({ projectId: projectId, typeId: this.form.value })
      this.fetching = false;
      if (!err) {
        this.disclosurePlan = res.data
      }
    },
    initTitle() {
      switch (this.form.value) {
        case 3:
          this.$route.meta.title = "新增危险源辨识会议"
          break
        case 2:
          this.$route.meta.title = "新增专业分包方案讲评记录"
          break
        case 1:
          this.$route.meta.title = "新增施组方案评审会议记录"
          break
        default:
          break
      }
    },
    getTime(date, dateString, type, name) {
      this[type][name] = dateString
      console.log(this[type][name])
    },
    async getMeetingType() {
      const [err, res] = await getMeetingType()
      if (!err) {
        this.meetingTypeList = res.data.filter(v=>v.id!=='648785280249237505').map((item) => {
          item.value = item.category
          item.label = item.name
          return item
        })
        console.log(this.meetingTypeList)
      }
    },
    delItem(idx) {
      this.form.fileList.splice(idx, 1)
      this.$refs.table.refresh(true)
      console.log(this.form.fileList)
    },
    fileArrysData: function(val) {
      this.form.fileList = val
      this.$refs.table.refresh(true)
    },

    onChangeRadio(e) {
      console.log(e)
    },
    onChange(e) {
      console.log(e)
      // this.form.value = e.target.value
    },
    onSelectChange(e) {
      console.log("selectedRowKeys changed: ", e)
    },
    commentsVal: function(val) {
      console.log(val)
      this.form.meetingSummary = val
    },
    handleClose() {
      this.$multiTab.close(this.$route.fullpath)
      //  history.go(-1)
    },
    //基本会议
    validateForm() {
      let flag = false
      this.$refs.ruleForm.validate((valid) => {
        flag = valid
        if(!valid) {
          this.$message.warning("请填写完所有必填项信息")
        }
      })
      return flag
    },
    //施工方案评审会议
    validateFormRule(rule) {
      let flagrule = true
      let flagbasis = false

      if (rule == 4 || rule == 6) {
        flagbasis = this.validateForm()
        return flagbasis
      } else {
        flagbasis = this.validateForm()
      }
      if (rule == 9) {
        rule = 8
      }
      let ruleForm = "ruleForm" + rule
      console.log(ruleForm)
      this.$refs[ruleForm].validate((valid) => {
        if(!valid) {
          this.$message.warning("请填写完所有必填项信息")
          return
        }
        flagrule = valid
      })

      if (flagrule && flagbasis) {
        return true
      } else {
        this.$message.warning("表单填写不完整")
        return false
      }
    },
    changeValue() {
      for (let i = 1; i < 8; i++) {
        if (i != 4 && i != 6) {
          let ruleForm = "ruleForm" + i
          console.log(ruleForm)
          this.$refs[ruleForm].resetFields()
        }
      }
    },

    async addMeeting() {
      const rule = this.form.value
      if (!this.validateFormRule(rule)) return
      if (rule == 8 || rule == 9) {
        if (this.form.meetingSummary == "") {
          this.$message.warning("请填写会议纪要")
          return
        }
      } else {
         if(rule == 7 && this.form.isProSub){   //为施组方案并且为专业分包
          if (this.form.sitPhotoList.length == 0) {
          this.$message.warning("请上传现场照片")
          return
        }
        if (this.form.summaryFileList.length == 0) {
          this.$message.warning("请上传附件")
          return
        }
         }else{
          if (this.form.meetingEmployeeDTOListData.length == 0) {
          this.$message.warning("请选择参会人员")
          return
        }
        }
      }
      this.form.meetingEmployeeDTOList = []
      this.form.meetingEmployeeDTOListData.forEach((item) => {
        this.form.meetingEmployeeDTOList.push(item.id)
      })
      const params = {
        ...this.form,
        meetingTypeId: this.meetingTypeList.filter((item) => this.form.value == item.category)[0].id
      }
      this.loading = true
      const [err, res] = await addMeeting(params)
      this.loading = false
      if (!err) {
        this.$message.success("新增成功")
        this.handleClose()
      }
    }
  }
}
</script>
<style lang='less' scoped>
@deep: ~'>>>';
.tool-btns {
  display: flex;
  justify-content: flex-end;

  @{deep} .ant-btn + .ant-btn {
    margin-left: 12px;
  }
}

.row {
  display: flex;
  flex-direction: row;
}
</style>
